package com.hdd.hll.modules.order.web;

import com.hdd.hll.common.response.Response;
import com.hdd.hll.common.response.ResponseUtils;
import com.hdd.hll.common.utils.StringUtils;
import com.hdd.hll.modules.order.bean.PoundOrder;
import com.hdd.hll.modules.order.bean.PoundUpdateOrder;
import com.hdd.hll.modules.order.service.PoundService;
import com.hdd.hll.modules.order.web.dto.Pound2Dto;
import com.hdd.hll.modules.order.web.dto.PoundDto;
import com.hdd.hll.modules.order.web.dto.PoundUpdateDto;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;


@RestController
@RequestMapping(value = "/pound")
@Slf4j
@Api(value="磅单controller",tags={"磅单数据"})
public class PoundController {

    @Autowired
    PoundService poundService;

    @ApiOperation(value="磅单数据，根据调拨单进行分类查询" ,httpMethod="POST")
    @RequestMapping(value="/findPoundsByPlanId", method= RequestMethod.POST)
    public Response<List<PoundOrder>> findPage(@RequestBody Pound2Dto dto){
        log.info("磅单数据-请求参数：,{}",dto);
        if(StringUtils.isNullOrEmpty(dto)){
            return ResponseUtils.initsByCode("common.param.empty");
        }
        if(dto.getDataSize()>10000){
            return ResponseUtils.initsByCode("common.data.large");
        }
        if(dto.getDataSize()<=0){
            return ResponseUtils.initsByCode("common.data.small");
        }
        if(StringUtils.isNullOrEmpty(dto.getPoid())){
            return ResponseUtils.initsByCode("common.poid.empty");
        }
        List<PoundOrder> callOrders = poundService.findPounds(dto);
        log.info("磅单数据-返回参数：,{}",callOrders);
        return ResponseUtils.inits(callOrders);
    }


    @ApiOperation(value="磅单数据", httpMethod="POST")
    @RequestMapping(value="/findPounds", method= RequestMethod.POST)
    public Response<List<PoundOrder>> findPounds(
            @RequestBody PoundDto dto){
        log.info("磅单数据-请求参数：,{}",dto);
        if(StringUtils.isNullOrEmpty(dto)){
            return ResponseUtils.initsByCode("common.param.empty");
        }
        if(dto.getDataSize()>10000){
            return ResponseUtils.initsByCode("common.data.large");
        }
        if(dto.getDataSize()<=0){
            return ResponseUtils.initsByCode("common.data.small");
        }
        List<PoundOrder> callOrders = poundService.findPounds(dto);
        log.info("磅单数据-返回参数：,{}",callOrders);
        return ResponseUtils.inits(callOrders);
    }



    @ApiOperation(value="磅单修改数据", httpMethod="POST")
    @RequestMapping(value="/findPoundsUp", method= RequestMethod.POST)
    public Response<List<PoundUpdateOrder>> findPoundsUp(
            @RequestBody PoundUpdateDto dto){
        log.info("磅单修改数据-请求参数：,{}",dto);
        if(StringUtils.isNullOrEmpty(dto)){
            return ResponseUtils.initsByCode("common.param.empty");
        }
        if(dto.getDataSize()>10000){
            return ResponseUtils.initsByCode("common.data.large");
        }
        if(dto.getDataSize()<=0){
            return ResponseUtils.initsByCode("common.data.small");
        }
        List<PoundUpdateOrder> poundUpdateOrders = poundService.findPoundsUp(dto);
        log.info("磅单修改数据-返回参数：,{}",poundUpdateOrders);
        return ResponseUtils.inits(poundUpdateOrders);
    }

    @ApiOperation(value="磅单修改全部数据", httpMethod="GET")
    @RequestMapping(value="/findPoundsUpAll", method= RequestMethod.GET)
    public Response<List<PoundUpdateOrder>> findPoundsUpAll(){
        List<PoundUpdateOrder> poundUpdateOrders = poundService.findPoundsUpAll();
        log.info("磅单修改全部数据-返回参数：,{}",poundUpdateOrders);
        return ResponseUtils.inits(poundUpdateOrders);
    }
}
